﻿using SingleUserMall.Actives;
using SingleUserMall.Authorization.Users;
using SingleUserMall.Commissions;
using SingleUserMall.EntityFramework;
using SingleUserMall.Points;
using SingleUserMall.Sms;
using System.Linq;

namespace SingleUserMall.Migrations.SeedData
{
    class DefaultActivesCreator
    {
        private readonly SingleUserMallDbContext _context;

        public DefaultActivesCreator(SingleUserMallDbContext context)
        {
            _context = context;
        }

        public void Create()
        {
            CreateDefaultActives();
        }

        private void CreateDefaultActives()
        {
            User adminUser = _context.Users.FirstOrDefault(u => u.UserName == User.AdminUserName);
            if (adminUser != null)
            {
                var count = _context.Active.Count();
                if (count == 0)
                {
                    _context.Active.Add(new Active { Name="分享商品", Description="分享商品20次得200体验金" , Amount=200,  Times=20, Sort = 1, Enabled = true});
                    _context.Active.Add(new Active { Name = "邀请好友", Description = "邀请好友10次得200体验金", Amount = 200, Times = 10, Sort = 2, Enabled = true });
                }
                _context.SaveChanges();
            }
        }
    }
}
